<template>
    <!-- 顶部导航 -->
    <van-nav-bar title="新增收货地址" left-text="返回" left-arrow @click-left="onClickLeft" />

    <van-address-edit
        :area-list="areaList"
        show-set-default
        :area-columns-placeholder="['请选择', '请选择', '请选择']"
        @save="onSave"
    />
</template>
<script>
import { areaList } from '@vant/area-data';
import {showNotify} from 'vant'
export default {
    created() {
        // this.info = {
        //     name:this.LoginUser.nickname,

        // }
    },
    data() {
        return {
            areaList:areaList,
            LoginUser:this.$cookies.get('LoginAuth'),
            // info:{}
        }
    },
    methods: {
        onClickLeft()
        {
            this.$router.go(-1)
        },
        async onSave(value)
        {
            let data = {
                busid:this.LoginUser.id,
                consignee:value.name,
                mobile:value.tel,
                code:value.areaCode,
                status:value.isDefault ? 1:0,
                address:value.addressDetail
            }

            let result = await this.$api.AddressAdd(data)

            if(result.code === 1)
            {
                showNotify({
                    type:'success',
                    message:result.msg,
                    onClose:() => {
                        this.$router.push('/user/address/index')
                    }
                })

                return false
            }else{
                showNotify({
                    type:'warning',
                    message:result.msg
                })

                return false
            }
        }
    },
}
</script>